/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.yami.shop.live.api.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.param.LiveRoomParam;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.live.common.dto.LiveRoomDto;
import com.yami.shop.live.common.service.LiveRoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;


/**
 * @author lhd
 * @date 2020-08-05 08:53:17
 */
@RestController
@RequestMapping("/live/liveRoom" )
@Api(tags = "直播接口")
public class LiveRoomController {

    @Autowired
    private LiveRoomService liveRoomService;

    @GetMapping("/page" )
    @ApiOperation(value = "直播间列表信息", notes = "直播间列表信息")
    public ServerResponseEntity<IPage<LiveRoomDto>> getLiveRoomPage(PageParam<LiveRoomDto> page, LiveRoomParam liveRoomParam){
        // 如果type为空，则为搜索直播信息
        if(Objects.isNull(liveRoomParam.getSearchType())||StrUtil.isBlank(liveRoomParam.getName())){
            liveRoomParam.setSearchType(1);
            liveRoomParam.setName("");
        }
        liveRoomParam.setRoomTop(0);
        return ServerResponseEntity.success(liveRoomService.pageRoomAndDetail(page,liveRoomParam));
    }

    @GetMapping("/pageTopRoom" )
    @ApiOperation(value = "置顶直播间列表信息", notes = "置顶直播间列表信息")
    public ServerResponseEntity<IPage<LiveRoomDto>> getLiveRoomPageByTop(PageParam<LiveRoomDto> page){
        LiveRoomParam liveRoom = new LiveRoomParam();
        liveRoom.setRoomTop(1);
        liveRoom.setSearchType(1);
        liveRoom.setName("");
        return ServerResponseEntity.success(liveRoomService.pageRoomAndDetail(page,liveRoom));
    }
}
